//Powered By Webit Team, amdin_adu 2012 - 2014

package com.fas.hehe.system.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import cn.dreampie.tablebind.TableBind;

import com.jfinal.plugin.activerecord.Model;

@TableBind(tableName = "sys_role", pkName = "id")
public class Role extends Model<Role> {

	private static final long serialVersionUID = 1L;
	public static final Role dao = new Role();

	private List<Long> resourceIds;

	public List<Long> getResourceIds() {
		if (resourceIds == null) {
			resourceIds = new ArrayList<Long>();
		}
		return resourceIds;
	}

	public String getResourceIdsStr() {
		if (CollectionUtils.isEmpty(resourceIds)) {
			return "";
		}
		StringBuilder s = new StringBuilder();
		for (Long resourceId : resourceIds) {
			s.append(resourceId);
			s.append(",");
		}
		return s.toString();
	}

	public void setResourceIdsStr(String resourceIdsStr) {
		if (StringUtils.isEmpty(resourceIdsStr)) {
			return;
		}
		String[] resourceIdStrs = resourceIdsStr.split(",");
		for (String resourceIdStr : resourceIdStrs) {
			if (StringUtils.isEmpty(resourceIdStr)) {
				continue;
			}
			getResourceIds().add(Long.valueOf(resourceIdStr));
		}
	}
}
